<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/mobile/include/taglib.jsp"%>
<html>
<head>
	<title>商户信息</title>
	<%@include file="/WEB-INF/views/mobile/include/head.jsp" %>
	<script type="text/javascript"> 
	$(document).ready(function() {
			if('${merchant.logoUrl }'==''){
				$("#photo").css("display", "none");
			}
			
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element.parent());
					}
				}
			});
			
		});
		
		function showPhoto(path){
			$("#logoUrl").val(path);
			$("#photo").css("display", "block");
			var imageSrc = '${ctx}/download?filePath='+path;
			$("#photo").attr("src", imageSrc);
		}
		
		function showPopupDialog(){
			$("#popupDialog").popup("open");
			$("input[type='file']").show();
		}
		
		function uploadFun(){
		    if($("#uploadFile").val()=="") alert("请选择上传的图片.")
			else{
				showLoader("上传中...");
				//上传文件
			    $.ajaxFileUpload({
			    	type: "post",
			        url:'${ctx}/servlet/phonegapUp',//处理图片脚本
			        secureuri :false,
			        fileElementId :'uploadFile',//file控件id
			        dataType : 'json',
			        success : function (data){
			        	hideLoader();
			        	data = eval(data);
			            if(data.error == 0){
			            	alert("上传成功.");
			            	var url = data.url;
			            	showPhoto(url);
			            	$("#popupDialog").popup("close");
			            	$("input[type='file']").hide();
			            }else{
			            	alert(data.message);
			            }
			        },
			        error: function(data, e){
			            alert(e);
			        }
				});
			}
		}
	</script>
</head>
<body data-role="page">
	<div data-role="header" class="ui-header" data-position="fixed" data-tap-toggle="false">
		<div data-role="controlgroup" data-type="horizontal" class="ui-btn-left">
			<a href="${ctx }"><img class="head-back-icon" src="${ctxFront}/images/head/android/back.png"/></a>
	    </div>
	    <h1>商户信息</h1>
	    <div data-role="controlgroup" data-type="horizontal" class="ui-mini ui-btn-right">
	        <a href="javascript:" onclick="$('#inputForm').submit()" class="float-right"><img class="head-save-icon" src="${ctxFront}/images/head/android/save.png"/></a>
	    </div>
	</div>
	<div role="main" class="ui-content">
		<div id="popup" data-role="popup" data-position-to="window" data-overlay-theme="a" data-theme="b" class="ui-content">
		  <p></p>
		</div>
		<div data-role="popup" id="popupDialog" data-overlay-theme="b" data-theme="a" data-dismissible="false">
		    <div data-role="header" data-theme="a">
		    <h1>图片上传</h1>
		    </div>
		    <div role="main" class="ui-content">
		        <div class="file-box">
			     	<form id="uploadForm">
				          <input type="file" accept="image/*" name="uploadFile" id="uploadFile"  />
				          <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a" onclick="uploadFun()">上传</a>
				          <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a" data-rel="back">取消</a>
			      	</form>
			    </div>
		    </div>
		</div>
		<form:form id="inputForm" modelAttribute="merchant" action="${ctx}/ivm/merchant/info" method="post" >
			<form:hidden path="id"/>
			<tags:mbmessage content="${message}"/>
			<div data-role="fieldcontain">
		          <label for="name">商户名称:</label>
					<form:input path="name" htmlEscape="false" maxlength="50" class="required"/>
			</div>
			<div data-role="fieldcontain">
		          <label for="assisTitle">副标题:</label>
					<form:input path="assisTitle" htmlEscape="false" maxlength="50" class="required"/>
			</div>
			<div data-role="fieldcontain">
		          <label for="logoUrl">商店封面:</label>
		          	<form:hidden path="logoUrl" />
					<div class="photo">
						<c:if test="${merchant.id!=null}">
							<img id="photo" src="${ctx}/download?filePath=${merchant.logoUrl }" style="width:149px; height:84px;" />
						</c:if>
						<c:if test="${merchant.id==null}">
							<img id="photo" src="" style="width:149px; height:84px;" />
						</c:if>
					</div>
					<a href="#" onclick="showPopupDialog()" data-rel="popup" data-position-to="window" data-transition="pop" data-role="button" data-inline="true" data-icon="action" style="margin-top: 5px;">上传图片</a>
			</div>
			<c:if test="${merchant.id!=null}">
			<div data-role="fieldcontain">
		          <label for="shopUrl">商店链接:</label>
					<form:input path="shopUrl" readonly="true" htmlEscape="false" maxlength="200" class="required"/>
			</div>
			</c:if>
			<div data-role="fieldcontain">
		          <label>是否开放:</label>
		          	<form:radiobuttons path="openState" items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false" class="required" />
			</div>
			<div data-role="fieldcontain">
		          <label for="remarks">备注:</label>
					<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>
			</div>
			<div data-role="fieldcontain">
		          <label>账户信息:</label>
		         	<ol class="articleSelectList">
						<li>已清算金额：0.0元&nbsp;&nbsp;<input type="button" data-inline="true" value="明细"></li>
						<li>未清算金额：0.0元&nbsp;&nbsp;<input type="button" data-inline="true" value="明细"></li>
					</ol>
			</div>
		</form:form>
	</div>
	<%@include file="/WEB-INF/views/mobile/layouts/menu.jsp" %>
</body>
</html>